package com.tarry.shop.user.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.tarry.shop.constant.RegexpConstant;
import com.tarry.shop.user.enums.SexEnum;
import com.tarry.shop.validation.Add;
import com.tarry.shop.validation.Query;
import com.tarry.shop.validation.Update;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.io.Serializable;

/**
 * <p>
 * 用户信息表
 * </p>
 *
 * @author TARRY
 * @since 2021-11-23
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("t_user")
@ApiModel(value="User对象", description="用户信息表")
public class User extends Model<User> {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "用户ID")
    @TableId(value = "id", type = IdType.AUTO)
    @NotNull(message = "ID不能为空",groups = Update.class)
    private Integer id;

    @ApiModelProperty(value = "手机号")
    @NotBlank(message = "手机号不能为空",groups = Update.class)
    @Length(min = 11,max = 11,message = "手机号长度只能11位",groups = {Query.class,Update.class,Add.class})
    @Pattern(regexp = RegexpConstant.PHONE_REGEXP,message = "手机号格式错误")
    private String phone;

    @ApiModelProperty(value = "用户名")
    @NotBlank(message = "用户名不能为空",groups = {Add.class,Update.class})
    private String userName;

    @ApiModelProperty(value = "密码")
    @NotBlank(message = "密码不能为空",groups = {Add.class,Update.class})
    private String password;

    @ApiModelProperty(value = "性别")
    private SexEnum sex;

    @ApiModelProperty(value = "邮箱")
    @Pattern(regexp = RegexpConstant.EMAIL_REGEXP,message = "邮箱格式错误",groups = {Add.class,Update.class})
    private String email;


    @Override
    protected Serializable pkVal() {
        return this.id;
    }

}
